<?php
/**
** Author: Oleg Imanilov
** This script used to create JSON output from up to 3 files content.
** it looks for '<view>.html', '<view>.js' and '<view>.css' in 'view' directory, 
** than packs it's content into JSON.
**/
define("VIEW", "view/");

function template($tpl) {
	if(file_exists($tpl)) {
		ob_start();
		//You can use PHP inside any template, also $_GET, $_POST etc.
		include($tpl);
		$out = ob_get_contents();
		ob_end_clean();
		return $out;
	}
	return false;
}

$ret = new stdClass();
	
if(isset($_REQUEST['view'])) {
	$view = $_REQUEST['view'];
	$html = template(VIEW.$view.".html");
	if($html !== false) {
		$ret->html = $html;
	}
	$js = template(VIEW.$view.".js");
	if($js !== false) {
		$ret->js = $js;	
	}

	$css = template(VIEW.$view.".css");
	if($css !== false) {
		$ret->css = $css;	
	}
} 

echo json_encode($ret);

?>